;$(function () {
	getList();
})
var tale = new $.tale();//弹框

function getList() {
    $.ajax({
        url: ctxPath+"/set/navigation/getAll",
        type: 'GET',
        success: function (d) {
            var success = d.success;
            var result="";
            if (success == true) {
                var data = d.data;
                $.each(data,function(i,item){
                	result+='<div class="form-group">'
                	   +'<label class="col-sm-3 control-label">是否显示'+item.name+'</label>'
                	   +'<div class="col-sm-3">'
                	   +'<input style="display:none;" name="navigationList['+i+'].id" value="'+item.id+'">'
                	   +isCheck(i,item)
                	   +'</div>'
                	   +'</div>';
                })
                $("#navigation_list").html(result);
            }
        },
          error: function () {
        	
             }

    });
}

function isCheck(i,item){
	if(item.status==1){
	   return '<label class="radio-inline">'
   	   +'<input type="radio"  value="1" name="navigationList['+i+'].status" checked>显示'
   	   +'</label>'
   	   +'<label class="radio-inline">'
   	   +'<input type="radio"  value="2" name="navigationList['+i+'].status">隐藏'
   	   +'</label>';
	}else{
		 return '<label class="radio-inline">'
	   	   +'<input type="radio"  value="1" name="navigationList['+i+'].status" >显示'
	   	   +'</label>'
	   	   +'<label class="radio-inline">'
	   	   +'<input type="radio"  value="2" name="navigationList['+i+'].status" checked>隐藏'
	   	   +'</label>';	
	}
}

function saveInfo() {
    var json = $("#global-form").serializeFormJSON();
//    json =  JSON.stringify(json);
    console.log(json);
    url = ctxPath+"/set/navigation/updateInfo";
    $.ajax({
        url: url,
        type: 'POST',
        data: json,
        success: function (d) {
            var success = d.success;
            if (success) {
                tale.alertOk({
                    text: '保存成功',
                    then: function () {
                        setTimeout(function () {
                        	
                        	 window.location.href = ctxPath+'/set/navigation/list';
                        }, 500);
                    }
                });
            } else {
                tale.alertError(result.message || '保存失败');
            }
        }
    });
}
